<?php

namespace App\Exports\Platform;

use App\Exports\Export;

class SettlementExport extends Export
{

    /**
     * 映射标题行
     *
     * @return array
     */
    protected function headings(): array
    {
        return trans('view.platform.settlement.headings');
    }

    /**
     * 映射数据行
     *
     * @param \Illuminate\Database\Eloquent\Model $item
     * @return array
     */
    protected function map($item): array
    {
        return [
            timestamp_to_datetime($item->timed, isset($item->rates) ? 'month' : 'day'),
            $item->org->name ?? $item->plat_code,
            $item->currency,
            $item->bet_num,
            $item->amount,
            $item->rate ?? json_encode($item->rates),
            $item->revenue,
            $item->usd['bet_num'],
            $item->usd['amount'],
            $item->usd['revenue'],
        ];
    }

    /**
     * 初始化操作
     */
    protected function init()
    {
        // 文件名称
        $this->filename = trans('view.platform.settlement.filename');
    }
}
